cmake_minimum_required(VERSION 3.5)
project(projection)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()
set(CMAKE_BUILD_TYPE "Debug")
# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED

# find_package(PROJ REQUIRED)
# find_package(proj4 CONFIG REQUIRED)
    
# 1. add ROS2 dependency
find_package(rclcpp REQUIRED)



# 2. add protobuf library
set(Protobuf_PREFIX_PATH
    "/usr/local/protobuf/include"            
    "/usr/local/protobuf/lib"             
    "/usr/local/protobuf/bin" )
list(APPEND CMAKE_PREFIX_PATH "${Protobuf_PREFIX_PATH}")
message(STATUS ${CMAKE_PREFIX_PATH})
find_package(Protobuf REQUIRED)
if(PROTOBUF_FOUND)
    message(STATUS "protobuf library found")
else()
    message(FATAL_ERROR "protobuf library is needed but cant be found")
endif()

# 3. add google log library
#find_package(glog REQUIRED)
#if(glog_FOUND)
#    message(STATUS "glog library found")
#else()
#    message(FATAL_ERROR "glog library is needed but cant be found")
#endif()

# add INCLUDE directories
include_directories(
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_BINARY_DIR}/proto  # where the protobuf will be compiled into
  ${PROTOBUF_INCLUDE_DIRS}
  # ${PROJ_INCLUDE_DIRS}
  # /usr/include/proj
  ${rclcpp_INCLUDE_DIRS}
  ${std_msgs_INCLUDE_DIRS}
  ${msg_interfaces_INCLUDE_DIRS}
  ${CMAKE_CURRENT_SOURCE_DIR}/include
)




# executable
set(MAIN_SRC_LIST
  src/proj4.cpp
)

add_library(proj4 SHARED ${MAIN_SRC_LIST})
target_link_libraries(proj4 
  ${rclcpp_LIBRARIES}
  ${std_msgs_LIBRARIES}
  ${msg_interfaces_LIBRARIES}
  ${PROJ_LIBRARIES}
  # PROJ::proj 
  # PROJ4::proj
  proj

  #glog
)

# ament dependencies
ament_target_dependencies(proj4
  rclcpp 
)

ament_export_targets(proj4 HAS_LIBRARY_TARGET)

ament_export_dependencies(rclcpp)

# install

install(
  DIRECTORY include/
  DESTINATION include
)

install(TARGETS proj4
  EXPORT proj4 
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
  INCLUDES DESTINATION include)

# testing
if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # uncomment the line when a copyright and license is not present in all source files
  #set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # uncomment the line when this package is not in a git repo
  #set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
